
var interval = null; //倒计时函数
const app = getApp(); //获取应用实例
module.exports = {
  getDataRequest: getDataRequest, //网络请求封装
  setNavTitle: setNavTitle, //设置navigationTitle
  getWindowWidth: getWindowWidth, //获取设备屏幕大小
}
//网络请求封装
function getDataRequest(method, requedata, successCallBack, failCallBack) {
  requedata['id'] = wx.getStorageSync('id');
  var url = app.globalData.urlHeader + method;
  wx.request({
    url: url,
    method: "POST",
    data: requedata,
    header: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    success: function (res) {
      console.log(requedata, url, res);
      if (res.data.status == true || parseInt(res.data.status) == 200) {
        successCallBack(res.data)
      } else {
        wx.showModal({
          title: '提示',
          content: (res.data.msg == null ? '❌' : res.data.msg),
          showCancel: false,
          confirmText: '知道了',
        })
        failCallBack(res);
      }
    },
    fail: function (res) {
      failCallBack(res);
    }
  })
}

//设置navigationTitle
function setNavTitle(title) {
  wx.setNavigationBarTitle({
    title: title,
  })
}
//获取设备屏幕大小
function getWindowWidth(that) {
  wx.getSystemInfo({
    success: function (res) {
      that.setData({
        windowWidth: res.windowWidth,
        windowHeight: res.windowHeight,
      })
    }
  })
}
